package com.ruoyi;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;

import org.jasypt.encryption.StringEncryptor;
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;

import java.text.MessageFormat;
import java.util.Date;


public class Jiamitest {

    public static void main(String[] args) {
        f2();
    }

    public static void f2(){
        String format = MessageFormat.format("{0} aa {1}  cc {2}", "我是", "中國人", 99999);
        System.out.println(format);
    }

    public static void testjiami(){
        System.out.println(new Date());

        // 创建一个加密器实例，并设置算法、密钥和可能的盐值
        PooledPBEStringEncryptor encryptor = new MyJasyptConfig().CodeEncrypBean();
        encryptor.setAlgorithm("PBEWithMD5AndDES"); // 设置加密算法
        encryptor.setPassword("Pass@word1"); // 设置加密密钥

        // 如果使用了盐值，则还需要设置盐值
        // encryptor.setSaltGenerator(new RandomSaltGenerator());

        // 要解密的加密文本
        String encryptedText = "vyEUoqU2ybVQE00m5XBqfQMUWKTG7Y5f";

        // 解密文本
        String decryptedText = encryptor.decrypt(encryptedText);

        // 输出解密后的文本
        System.out.println("Decrypted text: " + decryptedText);
    }


    static class MyJasyptConfig {
        private static String ps = "Pass@word1";


        public  PooledPBEStringEncryptor CodeEncrypBean() {
            PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();

            SimpleStringPBEConfig config = new SimpleStringPBEConfig();

            config.setPassword(ps);
            config.setAlgorithm("PBEWithMD5AndDES");
            config.setKeyObtentionIterations("1000");
            config.setPoolSize("1");
            config.setProviderName("SunJCE");
            config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
            //config.setIvGeneratorClassName("org.jasypt.iv.RandomIvGenerator");
            config.setStringOutputType("base64");
            encryptor.setConfig(config);

            return encryptor;
        }
    }

}
